package com.craftplay.configuration;

import com.craftplay.interceptor.CookieInterceptor;
import com.craftplay.interceptor.LoginRequiredInterceptor;
import com.craftplay.interceptor.PermissionsInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Component
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    private CookieInterceptor cookieInterceptor;

    @Autowired
    private LoginRequiredInterceptor loginRequiredInterceptor;

    @Autowired
    private PermissionsInterceptor permissionsInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //微信登录 cookie 判断
        registry.addInterceptor(cookieInterceptor).excludePathPatterns("/play/weixin/authorize*").excludePathPatterns("/play/weixin/auth*").excludePathPatterns("/play/weixin/userInfo*").excludePathPatterns("/play/uploadImage").excludePathPatterns("/play/page/*");
        //微信登录
        registry.addInterceptor(loginRequiredInterceptor).excludePathPatterns("/play/weixin/authorize*").excludePathPatterns("/play/weixin/auth*").excludePathPatterns("/play/weixin/userInfo*").excludePathPatterns("/play/uploadImage").excludePathPatterns("/play/page/*");
        //管理页面权限
        registry.addInterceptor(permissionsInterceptor).addPathPatterns("/page/*");
        super.addInterceptors(registry);
    }

}
